<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">

          <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                   class="demo-ruleForm">
            <el-form-item>
              <div style="font-size: 40px;margin: 20px auto;">
                管理员登陆
              </div>
            </el-form-item>

            <el-form-item label="用户名" prop="username">
              <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input type="password" v-model="ruleForm.password" @keyup.enter.native="submitForm('ruleForm')" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" style="width: 100%" @click="submitForm('ruleForm')">登陆</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script>

import Cookies from 'js-cookie'
export default {
  data() {

    return {
      ruleForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          {required: true, message: '请输入活动名称', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入活动名称', trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$post('/user/open/login',this.ruleForm).then((res)=>{
            Cookies.set("token",res.data)
            this.$router.push("/userinfo/edit")
          })
        } else {
          return false;
        }
      });
    },
  }
}
</script>
<style scoped>
.demo-ruleForm {
  width: 500px;
  margin: 0 auto;
}

</style>